package ciyuan.Constants;

import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;

import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.function.Supplier;

public enum PlayerDataType {

    WATER("water", () -> 10000, (compoundNBT, value) -> compoundNBT.putInt("water", (int) value), compoundNBT -> compoundNBT.getInt("water")),
    MAGIC("magic", () -> 1000, (compoundNBT, value) -> compoundNBT.putLong("magic", castToLong(value)), compoundNBT -> compoundNBT.getLong("magic")),
    MAX_MAGIC("maxMagic", () -> 1000, (compoundNBT, value) -> compoundNBT.putLong("maxMagic", castToLong(value)), compoundNBT -> compoundNBT.getLong("maxMagic")),
    TEMPERATURE("temperature", () -> 37.0, (compoundNBT, value) -> compoundNBT.putDouble("temperature", (double) value), compoundNBT -> compoundNBT.getDouble("temperature")),
    EXP("exp", () -> 0, (compoundNBT, value) -> compoundNBT.putLong("exp", castToLong(value)), compoundNBT -> compoundNBT.getLong("exp")),
    LEVEL("level", () -> 0, (compoundNBT, value) -> compoundNBT.putInt("level", (int) value), compoundNBT -> compoundNBT.getInt("level")),
    STRENGTH("strength", () -> 0, (compoundNBT, value) -> compoundNBT.putInt("strength", (int) value), compoundNBT -> compoundNBT.getInt("strength")),
    STRONG("strong", () -> 0, (compoundNBT, value) -> compoundNBT.putInt("strong", (int) value), compoundNBT -> compoundNBT.getInt("strong")),
    AGILE("agile", () -> 0, (compoundNBT, value) -> compoundNBT.putInt("agile", (int) value), compoundNBT -> compoundNBT.getInt("agile")),
    WISDOM("wisdom", () -> 0, (compoundNBT, value) -> compoundNBT.putInt("wisdom", (int) value), compoundNBT -> compoundNBT.getInt("wisdom")),
    ANALYSIS("analysis", () -> 0, (compoundNBT, value) -> compoundNBT.putInt("analysis", (int) value), compoundNBT -> compoundNBT.getInt("analysis")),
    FLEXIBLE("flexible", () -> 0, (compoundNBT, value) -> compoundNBT.putInt("flexible", (int) value), compoundNBT -> compoundNBT.getInt("flexible")),
    STAMNA("stamina", () -> 0, (compoundNBT, value) -> compoundNBT.putInt("stamina", (int) value), compoundNBT -> compoundNBT.getInt("stamina")),
    ATTRBUTE_POINTS("attrbutePoints", () -> 0, ((compoundNBT, value) -> compoundNBT.putInt("attrbutePoints", (int) value)), compoundNBT -> compoundNBT.getInt("attrbutePoints")),
    SKILL_SLOT1("skillSlot1", () -> ItemStack.EMPTY, ((compoundNBT, value) -> compoundNBT.put("skillSlot1", ((ItemStack) value).serializeNBT())), compoundNBT -> compoundNBT.get("skillSlot1")),
    SKILL_SLOT2("skillSlot2", () -> ItemStack.EMPTY, ((compoundNBT, value) -> compoundNBT.put("skillSlot2", ((ItemStack) value).serializeNBT())), compoundNBT -> compoundNBT.get("skillSlot2")),
    SKILL_SLOT3("skillSlot3", () -> ItemStack.EMPTY, ((compoundNBT, value) -> compoundNBT.put("skillSlot3", ((ItemStack) value).serializeNBT())), compoundNBT -> compoundNBT.get("skillSlot3"));

    private final String name;
    public final Supplier getDefaultValue;
    public final BiConsumer<CompoundNBT, Object> putToNbt;
    public final Function<CompoundNBT, Object> getFromNbt;

    PlayerDataType(String name, Supplier getDefaultValue, BiConsumer<CompoundNBT, Object> putToNbt, Function<CompoundNBT, Object> getFromNbt) {
        this.name = name;
        this.getDefaultValue = getDefaultValue;
        this.putToNbt = putToNbt;
        this.getFromNbt = getFromNbt;
    }

    public String getName() {
        return name;
    }

    private static Long castToLong(Object value) {
        return Long.parseLong(String.valueOf(value));
    }

}
